﻿#pragma once
#include <osg/PrimitiveSet>

#include "Ent.h"

class JsonReader;

struct PlinePrivate;
struct PlineNode
{
	PlineNode() {}
	PlineNode(const osg::Vec3d& point, double bulge)
	{
		m_point = point;
		m_bulge = bulge;
	}
	osg::Vec3d m_point;
	//m_bulge > 0 -- 圆弧在弦矢量右侧
	//m_bulge < 0 -- 圆弧在弦矢量左侧
	//m_bulge = 0 -- 直线
	double m_bulge;//Chord Height
};

class Pline2D : public Ent2DCurve
{
	Q_OBJECT
public:
	Pline2D(INode* parent);
	void addNode(const osg::Vec3d& point, double bulge);
	const std::vector<PlineNode>& node() const;
	void setNode(const std::vector<PlineNode>& nodes);
	virtual std::shared_ptr<Ent> clone() const override;
	void setColor(const osg::Vec4 &color);
	int getNodeCount()const;
	const osg::Vec4& color() const;
	virtual void update3D() override;
	virtual osg::Node* getRep3D() const override;
	virtual void setSelected(bool val) override;
	virtual void save(QJsonObject &json) const;
	virtual void load(const QJsonObject& json, JsonReader& reader);
	void calHandles() const;
	virtual std::vector<osg::Vec3d> handles() const override;
	virtual void move(const osg::Vec3d& offset) override;
	virtual void scale(const osg::Vec3d& center, double scale) override;
	virtual void mirror(const osg::Vec3d& start, const osg::Vec3d& end) override;
	virtual void stretch(int index, const osg::Vec3d &offset) override;
	virtual void copy(const Ent& ent) override;
	virtual void rotate(const double angle, const osg::Vec2d& basePoint) override;
	virtual bool explode(std::vector<std::shared_ptr<Ent>>& result) const override;
	virtual std::vector<Handle(Geom2d_Curve)> getCurve2d() const override;
	virtual std::shared_ptr<Ent2DCurve> extend(bool front, double param, const gp_Pnt2d& point) const;
	virtual std::vector<std::shared_ptr<Ent2DCurve>> trim(const SectionParam& from, const SectionParam& to) const;
	virtual bool offset(double offset, const osg::Vec3d& offsetSide);
	virtual std::vector<std::shared_ptr<Ent3DCurve>> to3d();
	LEAF_METHODS;
protected:
	PlinePrivate* d_ptr;
};
